<?

/********************************************
* eventlist.php
*
* This page will display all available events for the user to choose
*
********************************************/

//include files
include "config.php";
include "../lib/db.php";
include "../lib/tbatv_lib.php";

$tba = new tbatvController();

$year = sanatizeGet($_GET['year']);
if (is_null($year) OR !is_numeric($year)) $year = date('Y');

$title = $year . " Events";

include "header.php";

?>

<h1><? echo $year ?> FIRST FRC Events</h1>

<?
//look up other years in the TBA system

$all_years = array();
foreach ($tba->getAllYears($year) as $old_year) {
    $all_years[] = "<a href=\"?year={$old_year}\">{$old_year}</a>";
}
$other_years_string = "<p><strong>Other Years: </strong>" . join(", ", $all_years) . "</p>\r\n";
print $other_years_string;

//Output this week's events.
if ($year == date('Y')) {
	$week = $tba->getCurrentWeek();
	$list_of_events = $tba->getEventsByWeek($week);
	if (count($list_of_events) > 0) {
		print "<h2>This Week: " . $tba->stringWeek($week) . "</h2>\r\n";
		foreach ($list_of_events as $event) {
			print $event->linkto() . "<br />\r\n";
		}
	}
}

//Output all week's events in blocks
foreach ($all_weeks as $week) {
	$list_of_events = $tba->getEventsByWeek($week, $year);
	if (count($list_of_events) > 0) {
		print "<h2>" . $tba->stringWeek($week) . "</h2>\r\n";
		foreach ($list_of_events as $event) {
			print $event->linkto() . "<br />\r\n";
		}
	}
}

include "footer.php";

?>